<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/views/common/taglib.jsp" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>修改地址</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="viewport" content="width=320.1, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <%@ include file="/WEB-INF/views/common/resource.jsp" %>
    <script>
        var ctx = '${ctx}';
    </script>
</head>
<body>
<div class="page form">
    <div class="input_box select">
        <span><font color="red">*</font>城市</span>
        <select id="city" onchange="chooseCity()">
            <c:forEach items="${cityAreaList}" var="list">
                <option value="${list.area_no}">${list.area_name}</option>
            </c:forEach>
        </select>
    </div>
    <div class="input_box select">
        <span><font color="red">*</font>区域</span>
        <select id="area">
            <c:forEach items="${cityAreaList}" var="list">
                <c:forEach items="${list.areaList}" var="list2">
                    <option class="area_option parent_id_${list2.parent_id}" value="${list2.area_no}">${list2.area_name}</option>
                </c:forEach>
            </c:forEach>
        </select>
    </div>
    <div class="input_box">
        <span><font color="red">*</font>收货地址</span>
        <input type="text" placeholder="请输入收货地址" id="address" value="${shop_info.address}" />
    </div>
    <input type="button" onclick="saveEdit()" value="确认修改" style="margin-top: 18px;" />
</div>
</body>
<script>
    //===============城市联动菜单==================
    $(document).ready(function(){
        $("#city").find("option[value='${shop_info.city}']").attr("selected",true);
        chooseCity();
        $("#area").find("option[value='${shop_info.area}']").attr("selected",true);
        $("#channel_type_no").find("option[value='${shop_info.channel_type_no}']").attr("selected",true);
    });

    //选择城市事件
    function chooseCity() {
        var city_no = $("#city option:selected").val();
        $('.area_option').hide();
        $('.parent_id_'+city_no).show();
        $('.parent_id_'+city_no+':first').each(function () {
            $("#area").find("option[value="+$(this).val()+"]").attr("selected",true);
        })
    }

    //保存编辑
    function saveEdit() {

        var city = $("#city option:selected").val();
        if(checkIsNull(city)){
            alertTips("请选择城市！");
            return false;
        }
        var area = $("#area option:selected").val();
        if(checkIsNull(area)){
            alertTips("请选择区域！");
            return false;
        }
        var address = $('#address').val();
        if(checkIsNull(address)){
            alertTips("请填写地址！");
            return false;
        }

        if(confirm("确认修改地址信息？")){
            $.ajax({
                type: "post",
                url: '/shop/editShopAddress.do',
                dataType: "json",
                data: {
                    'city':city,
                    'area':area,
                    'address':address
                },
                success: function(resp){
                    console.log(resp);
                    if(resp.result==="success"){
                        alertTips("修改成功！");
                        location.href=ctx+'/';
                    }else{
                        alertTips(resp.msg);
                    }
                }
            });
        }
    }
</script>

</html>
